package thread;

/**
 * Created with IntelliJ IDEA.
 * Description: 变量捕获代码测试
 * User: 王圆豪
 * Date: 2025-04-23
 * Time: 20:11
 */
class Test{
    int value = 0;
}

public class Demo10 {
    //private static boolean isFinal = false;
    public static void main(String[] args) throws InterruptedException {
        //boolean isFinal = false; 变量捕获
        Test test = new Test(); //引用类型可以修改值，但不能指向新的对象
        Thread thread = new Thread(()->{
            while (test.value == 0) {
                System.out.println("Hello thread!");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
            System.out.println("thread线程结束");
        });

        thread.start();

        Thread.sleep(3000);
        test.value = 1;
//        isFinal = true;

    }
}
